//
//  ST_SingleHumanST_PeculiarityCell.swift
//  btvideo
//
//  Created by mac on 2020/2/27.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SnapKit
import SwifterSwift
import HandyJSON

/**
 弃用
 */
class ST_SingleHumanST_PeculiarityCell: UICollectionViewCell {
    
    

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.contentView.backgroundColor = Color.white
        
        contentView.addSubview(cover_image_view)
        
        cover_image_view.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        contentView.addSubview(cover_mask_view)
        cover_mask_view.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        cover_mask_view.addSubview(mask_label)
        mask_label.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        
        contentView.addSubview(is_cover_sign_view)
        is_cover_sign_view.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-10)
            make.top.equalToSuperview().offset(10)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
//    fileprivate lazy var pauseSignImageView:UIImageView = {
//        let control = UIImageView.init(image: ST_ImageUtils.imageName("pause"))
//        control.isHidden = true
//        return control
//    }()
    
    
    fileprivate lazy var cover_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.cornerRadius = 20
        return control
    }()
    
    
    fileprivate lazy var cover_mask_view:UIView = {
        let control = UIView()
        control.backgroundColor = UIColor.init(white: 0, alpha: 0.4)
        control.isHidden = true
        control.cornerRadius = 20
        return control
    }()
    
    fileprivate lazy var mask_label:UILabel = {
       let control = UILabel()
        control.text = "审核中.."
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.semibold)
        control.textColor = .white
        control.textAlignment = .center
        return control
    }()
    
    fileprivate lazy var is_cover_sign_view:UIImageView = {
        let control = UIImageView.init(image: ST_ImageUtils.imageName("特质_icon_封面")!)
        control.isHidden = true
        return control
    }()

//    MARK: - Bind Model
    var model = ST_SingleHumanST_PeculiarityCellModel(){
        didSet{
            
            cover_image_view.pin_setImage(from: model.content.compress_image().url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
            
//            功能 #3913
//            cover_mask_view.isHidden = model.state != 1
            
        }
    }
    
    var isCover = false{
        didSet{
            is_cover_sign_view.isHidden = !isCover
        }
    }
}


extension ST_SingleHumanST_PeculiarityCell:ST_PecGroupshareViewRectProtocol {
    
    func picutreframe_in_content_view() -> CGRect {
        return self.cover_image_view.frame
    }
    
}



//MARK: - MODEL
class ST_SingleHumanST_PeculiarityCellModel: NSObject,HandyJSON {
    
    var id = 0
    
    var type = 0
    
    var video_url = ""
    
    var content = ""
    
    var width:Float = 0
    
    var height:Float = 0
    
    var view_count = 0

    var group_id = 0
//    等于 1  审核中
    var state = 0
    
    var remark = ""
    
    var thumb_up_count = 0
    
    var is_thumb_up = false
    
    var is_attention = false
    
    required override init() {
        super.init()
    }
    
    func convert_to_trait_cell_model(userID:String,peculiarity_id:Int)->ST_TraitOfOperatCellModel{
        
        let model = ST_TraitOfOperatCellModel()
        
        model.state = self.state
        
//        feature_id = json["feature_id"].intValue
        model.feature_id = peculiarity_id
        
        model.group_id = self.group_id
        
        model.accid = userID
        if self.video_url.count > 3{
            model.videoUrl = self.video_url
        }
        
        model.imageUrl = self.content
                
        //        类型(1:视频,2:图片)
        if model.videoUrl.count > 3{
            model.type = .video
        }
        model.sign = self.remark
                
        model.width = self.width.cgFloat
                
        model.height = self.height.cgFloat
        
        model.thumbUpCount = self.thumb_up_count
        
        model.isThumbUp = self.is_thumb_up
        
        model.isAttention = self.is_attention
        
        model.create_view_model_set(maxContentHeight: ST_ShowTraitCell.two_line_max_height)
        
        return model
    }
    
}



